package com.axx.android.base;

import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;

import com.axx.android.LetterApp;
import com.axx.android.R;
import com.axx.android.common.Constants;
import com.axx.android.profile.auth.activity.LoginActivity;
import com.axx.android.profile.auth.model.LoginEvent;
import com.axx.android.utils.ToastUtils;


import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import butterknife.ButterKnife;

public abstract class BaseActivity extends AppCompatActivity implements BaseView {

    private Dialog dialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutId());
        ButterKnife.bind(this);
        init(savedInstanceState);

        Button mBack = (Button) findViewById(R.id.btn_back);
        if (mBack != null) {
            mBack.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    finish();
                }
            });
        }


    }

    public abstract int getLayoutId();

    public abstract void init(Bundle savedInstanceState);


    @Override
    public void showToast(String msg) {
        ToastUtils.showShortToast(this, msg);
    }

    @Override
    public void showLoading(String msg) {
        dialog = new Dialog(this, R.style.DialogStyle);
        dialog.setContentView(R.layout.view_loading);
        dialog.show();
    }

    @Override
    public void hideLoading() {
        if (dialog != null)
            dialog.dismiss();
    }

    @Override
    public void showErrorParse() {
        showToast(Constants.ERROR_PARSE);
    }

    @Override
    public void showErrorNet() {
        showToast(Constants.ERROR_NET);
    }


    public void startCheckAuth(Intent intent) {
        if (LetterApp.authUser == null) {
            startActivity(new Intent(this, LoginActivity.class));
        } else {
            startActivity(intent);
        }
    }
}
